using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using UwinEducation.Shared.Enums;

namespace UwinEducation.Domain.Entities
{
    /// <summary>
    /// 订单实体
    /// </summary>
     [Table("orders")]
    public class Order : EntityBase
    {
        /// <summary>
        /// 订单ID
        /// </summary>
        public Guid Id { get;  set; }

        /// <summary>
        /// 学生ID
        /// </summary>
        public Guid StudentId { get;  set; }

        /// <summary>
        /// 订单编号
        /// </summary>
        public string OrderNumber { get;  set; }

        /// <summary>
        /// 创建日期
        /// </summary>
        public DateTime CreatedDate { get;  set; }

        /// <summary>
        /// 订单说明
        /// </summary>
        public string Description { get;  set; }

        /// <summary>
        /// 支付状态
        /// </summary>
        public PaymentStatus PaymentStatus { get;  set; }

        /// <summary>
        /// 总价
        /// </summary>
        public decimal TotalAmount { get; set; } // 存储计算后的总价（详情单价*数量）

        /// <summary>
        /// 总的折扣金额
        /// </summary>
        public decimal DiscountedAmount { get; set; } // 折扣后总价

        /// <summary>
        /// 总支付金额
        /// </summary>
        public decimal PaidAmount { get; set; } // 总支付金额

        /// <summary>
        /// 学生导航属性
        /// </summary>
        public virtual Student Student { get;  set; }

        /// <summary>
        /// 订单详情集合
        /// </summary>
        public virtual List <OrderDetail> OrderDetails { get; set; } = new List<OrderDetail>();

        /// <summary>
        /// 订单折扣集合
        /// </summary>
        public virtual List<OrderDiscount> OrderDiscounts { get; set; } = new List<OrderDiscount>();

        /// <summary>
        /// 订单支付集合
        /// </summary>
        public virtual List<OrderPayment> OrderPayments { get; set; } = new List<OrderPayment>();

        /// <summary>
        /// 预约集合
        /// </summary>
        public virtual List<Appointment> Appointments { get; set; } = new List<Appointment>();



        protected Order() { }

        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="studentId">学生ID</param>
        /// <param name="orderNumber">订单编号</param>
        /// <param name="description">订单说明</param>
        /// <returns>订单实体</returns>
        public static Order Create(
            Guid studentId, 
            string orderNumber, 
            string? description,
            DateTime createdDate)
        {
            return new Order
            {
                Id = Guid.NewGuid(),
                StudentId = studentId,
                OrderNumber = orderNumber,
                Description = description??string.Empty,
                PaymentStatus = PaymentStatus.Unpaid,
                TotalAmount = 0,
                DiscountedAmount = 0,
                PaidAmount = 0,
                CreatedDate = createdDate
            };
        }
    }

} 